package org.crmsystem.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.crmsystem.dao.JobMapper;
import org.crmsystem.dao.StaffMapper;
import org.crmsystem.model.Job;
import org.crmsystem.model.Staff;
import org.crmsystem.service.IJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * 职务服务层实现
 * @author 孙艳平
 *
 */
@Service
public class JobServiceImpl implements IJobService {
	@Autowired
	private JobMapper jobMapper;
	@Autowired
	private StaffMapper staffMapper;
	/**
	 * 根据id获取部门详细信息
	 */
	public Job getJobById(int id) {
		return jobMapper.getJobById(id);
	}
	/**
	 * 多条件查询获取部门列表
	 */
	public List<Job> getJob(Job job) {
		return jobMapper.getJob(job);
	}
	/**
	 * 添加部门
	 */
	public int addJob(Job job) {
		return jobMapper.addJob(job);
	}
	/**
	 * 删除部门
	 */
	@Transactional
	public int delJob(int id) {
		Staff staff=new Staff();
    	staff.setJobId(id);
    	Map map=new HashMap();
    	map.put("staff", staff);
    	map.put("currPage", 0);
    	map.put("pageSize", 0);
    	List<Object> list=staffMapper.getStaff(map);
    	for(int i=0;i<list.size();i++){
    		Staff staff1=(Staff)list.get(i);
    		staff1.setJobId(-1);
    		int flag=staffMapper.updateStaff(staff1);
    	}
        return jobMapper.delJob(id);
	}
	/**
	 * 更新部门
	 */
	public int updateJob(Job job) {
		return jobMapper.updateJob(job);
	}
	

}
